package org.fintan.make.controller;

import org.fintan.make.master.ExecuteResult;
import org.fintan.make.params.UserParam;
import org.fintan.make.service.LogInService;
import org.fintan.make.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(description = "登陆相关接口文档")
public class LogInController {

	Logger log = LoggerFactory.getLogger(getClass());
	@Autowired
	private LogInService logInService;
	
	@ApiOperation(value = "用户登陆", notes = "用户登陆")
	@RequestMapping(value = "login", method = RequestMethod.POST)
	@ApiImplicitParam(name = "user", value = "用户", dataType="User",paramType="body")
	public ExecuteResult<?> login(@RequestBody UserParam param){
		
		if(StringUtils.isEmpty(param.getUserName())){
			log.info("用户名为空");
			return ExecuteResult.fail("用户名为空");
		}else if(StringUtils.isEmpty(param.getPassword())){
			log.info("用户密码为空");
			return ExecuteResult.fail("用户密码为空");
		}
		
		return logInService.logIn(param);
	}

}
